//webServer代码
void webServerSetup(){
      //webServer初始化
    while (!Serial) {

  }
  Serial.println("Ethernet WebServer Example");
  Ethernet.begin(mac, ip);
  if (Ethernet.hardwareStatus() == EthernetNoHardware) {
    Serial.println("Ethernet shield was not found.  Sorry, can't run without hardware. :(");
    while (true) {
      delay(1); // do nothing, no point running without Ethernet hardware
    }
  }
  if (Ethernet.linkStatus() == LinkOFF) {
    Serial.println("Ethernet cable is not connected.");
  }

  // start the server
  server.begin();
  Serial.print("server is at ");
  Serial.println(Ethernet.localIP());
}


void webServer() {
  // listen for incoming clients
  EthernetClient client = server.available();
  if (client) {
    Serial.println("new client");
    // an http request ends with a blank line
    boolean currentLineIsBlank = true;
    while (client.connected()) {
      if (client.available()) {
        char c = client.read();
        Serial.write(c);
        // if you've gotten to the end of the line (received a newline
        // character) and the line is blank, the http request has ended,
        // so you can send a reply
        if (c == '\n' && currentLineIsBlank) {
          // send a standard http response header
          client.println("HTTP/1.1 200 OK");
          client.println("Content-Type: text/html;charset=utf-8");
          client.println("Connection: close");  // the connection will be closed after completion of the response
          client.println("Refresh: 2");  // refresh the page automatically every 2 sec
          client.println();
          client.println("<!DOCTYPE HTML>");
          client.println("<html>");
          client.println("<head><title>空中菜园状态监控</title></head>");
          
                       
            //显示当前温度湿度
            client.print("天气温湿度:");
            client.println("<br />");
            client.print("温度(C): ");
            client.println((float)DHT11.temperature, 2);
            client.print("湿度(%): ");
            client.println((float)DHT11.humidity, 2);
            client.println("<hr />");

            //显示当前各项电压
            client.print("各项电压状态:");
            client.println("<br />");
            client.print("太阳能电压: ");
            client.println(dianYa_taiYangNeng);
            client.print("V");
            client.println("<br />");
            client.print("电池电压: ");
            client.println(dianYa_dianChi);
            client.print("V");
            client.println("<br />");                                                                                                                                              
            client.print("主板电压: ");
            client.println(dianYa_zhuBan);
            client.print("V");
            client.println("<hr />");
              
            //显示当前土壤电阻值及土壤湿度
            
            

            //水箱满空
            client.print("储水箱状态:");
            client.println("<br />");
            if(shuiWei_Man == LOW  && shuiWei_Kong == LOW){
              client.print("储水箱已满，关闭水龙头！");
            }else if(shuiWei_Man == HIGH && shuiWei_Kong == LOW){
              client.print("储水箱里有水，但不满，水龙头关闭，等候雨水！");
            }else if(shuiWei_Man == HIGH  && shuiWei_Kong == HIGH && yuShuiDianZu>=1000){
              client.print("储水箱已空，并且无雨水，打开水龙头！");
            }
              client.println("<hr />");

            //雨水检测
            client.print("雨水感应器:");
            client.println("<br />");
            client.print("雨水感应器电阻:");
            client.println(yuShuiDianZu);
            client.println("<br />");
            if(yuShuiDianZu<1000){
              client.print("下雨了！");
            }else{
              client.print("无雨！");
            }
              client.println("<hr />");

            //灌溉情况
            client.print("菜园灌溉状态:");
            client.println("<br />");
            
            //菜园1
            client.print("菜园1的土壤电阻=");
            client.print(tuRangDianZu_1);
            client.print("  土壤湿度=");
            client.println(tuRangShiDu_1);
            client.println("<br />");
            
            if(tuRangShiDu_1<60 && shuiWei_Kong==LOW){  //如果土壤湿度低于60，且水箱不空，开始灌溉。
              client.println("菜园1正在灌溉！");
              }else if(shuiWei_Kong==HIGH){  //如果水箱空，停止灌溉。
              client.println("储水箱已空，菜园1停止灌溉！");
              }else if(tuRangShiDu_1>70){  //如果土壤湿度达到70以上，停止灌溉。
                client.println("菜园1土壤已达到既定湿度，停止灌溉！");
              }else{
                client.println("未知情况，停止灌溉！");
              }
              client.println("<hr />");
              
            //菜园2
            client.print("菜园2的土壤电阻=");
            client.print(tuRangDianZu_2);
            client.print("  土壤湿度=");
            client.println(tuRangShiDu_2);
            client.println("<br />");
            
            if(tuRangShiDu_2<60 && shuiWei_Kong==LOW){  //如果土壤湿度低于60，且水箱不空，开始灌溉。
              client.println("菜园2正在灌溉！");
              }else if(shuiWei_Kong==HIGH){  //如果水箱空，停止灌溉。
              client.println("储水箱已空，菜园2停止灌溉！");
              }else if(tuRangShiDu_2>70){  //如果土壤湿度达到70以上，停止灌溉。
                client.println("菜园2土壤已达到既定湿度，停止灌溉！");
              }else{
                client.println("未知情况，停止灌溉！");
              }
              client.println("<hr />");
              
              
          client.println("</html>");
          break;
        }
        if (c == '\n') {
          // you're starting a new line
          currentLineIsBlank = true;
        } else if (c != '\r') {
          // you've gotten a character on the current line
          currentLineIsBlank = false;
        }
      }
    }
    // give the web browser time to receive the data
    delay(1);
    // close the connection:
    client.stop();
    Serial.println("client disconnected");
  }
}
